package com.example.first;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class RateActivity extends AppCompatActivity {

    EditText rmb;
    TextView show;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate);

        rmb = (EditText) findViewById(R.id.rmb);
        show = (TextView) findViewById(R.id.showOut);
    }

    public void onClick(View btn){
        //获取用户输入内容
        String str = rmb.getText().toString();
        float r = 0;
        if(str.length()>0){
             r = Float.parseFloat(str);
        }else {
            //提示用户输入内容
            Toast.makeText(this, "请输入金额", Toast.LENGTH_SHORT).show();
        }

        float val = 0;
        if(btn.getId()==R.id.btn_dollar){
              val = r * (1/6.5f);
         }else if(btn.getId()==R.id.btn_euro){
             val = r * (1/7.8f);
        }else if(btn.getId()==R.id.btn_won) {
             val = r * 173;
        }
        show.setText(String.format("%.2f",val));
    }

    public void openOne(View btn){
        //打开一个页面Activity
        Log.i("open","openOne");
        Intent config = new Intent(this,ConfigActivity2.class);

        startActivity(config);
    }
}